﻿using System;

namespace UFrameWork
{
    /// <summary>
    /// 控制器基类
    /// </summary>
    public class UController
    {
        /// <summary>
        /// 框架实例
        /// </summary>
        private UWork work = UWork.Instance;


        /// <summary>
        /// 执行Action
        /// </summary>
        /// <param name="key">命令名称</param>
        /// <param name="objs">参数列表</param>
        /// <returns></returns>
        protected void Action(string key, params object[] objs)
        {
            work.Do(key, objs);
        }

        /// <summary>
        /// 执行Action并返回结果
        /// </summary>
        /// <typeparam name="T">返回数据类型</typeparam>
        /// <param name="key">命令名称</param>
        /// <param name="objs">参数列表</param>
        /// <returns></returns>
        protected T Action<T>(string key, params object[] objs)
        {
            return work.Do<T>(key, objs);
        }

        /// <summary>
        /// 日志记录
        /// </summary>
        /// <param name="obj">日志内容</param>
        /// <param name="level">日志级别</param>
        /// <param name="tag">标签</param>
        public  void Log(object obj, LogLevel level = LogLevel.Debug, string tag = null)
        {
            if (tag == null) tag = GetType().Name;
            work.Log(obj, level, tag);
        }
    }
}